var app = getApp();
var http_service = app.data.service;
Page({
  data: {
    http_service: http_service,
    storeId: 0,
    store_name: '',
    serviceId: 0,
    service_name: '',
    price: 0,
    c_date:'',
    c_time:'',
    date:'',
    technician:[]
  },
  onLoad: function (options) {
    var that = this;
    this.setData({
      storeId: options.storeId,
      store_name: options.store_name,
      serviceId: options.serviceId,
      price: options.price,
      service_name: options.service_name,
      c_date: options.c_date,
      c_time: options.c_time,
      date: options.date,
    }, function () {
      wx.request({
        url: http_service+'/index.php/getalltechnician',
        data:{
          store_id:that.data.storeId,
          c_time: options.c_time,
          c_date: options.c_date,
          serviceId: options.serviceId,
        },
        success:function(res){
          that.setData({
            technician:res.data
          })
        }
      })
    })
  },

  changeTechnician:function(e){
    var that = this;
    var obj = e;
    var tecId = obj.currentTarget.id;
    var wait = 0;
    var technician = that.data.technician;
    for(var i = 0; i<technician.length;i++){
      if (tecId == technician[i]['id']){
        wait = technician[i]['wait'];
       
      }
    }
    var num = Math.ceil(wait/30);
    var time = ['8:30','9:00', '9:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30',
      '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00',
      '16:30', '17:00', '17:30', '18:00', '18:30', '19:00'];
    var index = time.indexOf(that.data.c_time);
    index = index+num;
    var c_time = time[index];
    var date = that.data.c_date+" "+c_time+"点";
    wx.setStorage({
      key: 'affirm',
      data: {
        storeId: that.data.storeId,
        store_name: that.data.store_name,
        serviceId: that.data.serviceId,
        price: that.data.price,
        service_name: that.data.service_name,
        tec_id: tecId,
        c_date: that.data.c_date,
        c_time:c_time ,
        date:date
      },
      success:function(){
        wx.navigateBack({
          delta: 1
        })
      }
    })
  }
})  
